
//
//  LoginViewController.m
//  MJApp
//
//  Created by 王亮 on 15/8/25.
//  Copyright (c) 2015年 王亮. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginInViewController.h"
#import "RegisterViewController.h"
#import "FindPasswordViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initUI];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initUI {
    
    self.view.backgroundColor = Color_Back_Black;
    UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    closeBtn.center = CGPointMake(IOS_IPHONE_WINDOW_WIDE - CGRectGetWidth(closeBtn.frame) * 0.5 - 10, 64 - CGRectGetHeight(closeBtn.frame) * 0.5);
    [closeBtn setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
    [self.view addSubview:closeBtn];
    [closeBtn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(closeBtn.frame), 90, 90)];
    headImageView.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, headImageView.center.y);
    headImageView.image = [UIImage imageNamed:@"head"];
    headImageView.layer.cornerRadius = CGRectGetWidth(headImageView.frame) / 2;
    headImageView.clipsToBounds = YES;
    [self.view addSubview:headImageView];
    
    UIImage *nameImage = [UIImage imageNamed:@"登陆_03"];
    UIImageView *nameImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headImageView.frame) + 20, nameImage.size.width, nameImage.size.height)];
    nameImageView.image = nameImage;
    nameImageView.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, nameImageView.center.y);
    [self.view addSubview:nameImageView];
    
    UIButton *loginBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(nameImageView.frame) + 20, CGRectGetWidth(self.view.frame) * 0.6, 30)];
    loginBtn.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, loginBtn.center.y);
    [loginBtn setTitle:@"登 录" forState:UIControlStateNormal];
    loginBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    loginBtn.layer.cornerRadius = CGRectGetHeight(loginBtn.frame) / 2;
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    loginBtn.backgroundColor = RGB(228, 41, 9);
    [loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginBtn];
    
    UIButton *registerBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(loginBtn.frame) + 20, CGRectGetWidth(self.view.frame) * 0.6, 30)];
    registerBtn.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, registerBtn.center.y);
    [registerBtn setTitle:@"一键注册" forState:UIControlStateNormal];
    registerBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    registerBtn.layer.cornerRadius = CGRectGetHeight(registerBtn.frame) / 2;
    [registerBtn setTitleColor:RGB(228, 41, 9) forState:UIControlStateNormal];
    registerBtn.backgroundColor = [UIColor whiteColor];
    [registerBtn addTarget:self action:@selector(resigter) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registerBtn];
    
    UILabel *descLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(registerBtn.frame) + 20, 100, 30)];
    descLabel.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, descLabel.center.y);
    descLabel.text = @"社交媒体登录";
    descLabel.font = [UIFont systemFontOfSize:15];
    descLabel.textColor = [UIColor whiteColor];
    descLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:descLabel];
    
    UIImage *weixinImage = [UIImage imageNamed:@"weixin"];
    UIImage *weiboImage = [UIImage imageNamed:@"weibo"];
    UIImage *QQImage = [UIImage imageNamed:@"QQ"];
    UIButton *weixinBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(descLabel.frame) + 10, weixinImage.size.width, weixinImage.size.height)];
    weixinBtn.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, weixinBtn.center.y);
    [weixinBtn setImage:weixinImage forState:UIControlStateNormal];
    [self.view addSubview:weixinBtn];
    UIButton *weiboBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,0, weixinImage.size.width, weixinImage.size.height)];
    weiboBtn.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2 - weixinImage.size.width - 20, weixinBtn.center.y);
    [weiboBtn setImage:weiboImage forState:UIControlStateNormal];
    [weiboBtn addTarget:self action:@selector(weiBo) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:weiboBtn];
    UIButton *QQBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, weixinImage.size.width, weixinImage.size.height)];
    QQBtn.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2 + weixinImage.size.width + 20, weixinBtn.center.y);
    [QQBtn addTarget:self action:@selector(QQ) forControlEvents:UIControlEventTouchUpInside];
    [QQBtn setImage:QQImage forState:UIControlStateNormal];
    [self.view addSubview:QQBtn];
    
    UIButton *forgetBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(weixinBtn.frame) + 20, 100, 30)];
    [forgetBtn setTitle:@"忘记密码?" forState:UIControlStateNormal];
    forgetBtn.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, forgetBtn.center.y);
    [self.view addSubview:forgetBtn];
    [forgetBtn addTarget:self action:@selector(forget) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)close {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)login {
    
    LoginInViewController *loginInVC = [[LoginInViewController alloc] init];
    [self.navigationController pushViewController:loginInVC animated:YES];
}

- (void)resigter{
    
    RegisterViewController *registerVC = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:registerVC animated:YES];
}

- (void)weiXin {
    
}

- (void)weiBo {
    
    
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response) {
        
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        dic[@"type"] = @"2";
        dic[@"open_id"] = response.data[@"sina"][@"usid"];
        dic[@"nickName"] = response.data[@"sina"][@"username"];
        dic[@"head"] = response.data[@"sina"][@"icon"];

    });

}

- (void)QQ {
    
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
    });
}

- (void)forget {
    
    FindPasswordViewController *findVC = [[FindPasswordViewController alloc] init];
    [self.navigationController pushViewController:findVC animated:YES];
}

@end
